(in-package #:colloquia)

#+nil (assert (equal (with-input-from-string (in "Titulus: De incomparabili heroe Joanne Reuchlino in divorum numerum relato.
                              Personæ: Pompilius, Brassicanus.")
                         (coll-read-header in))
 '((TITULUS "De incomparabili heroe Joanne Reuchlino in divorum numerum relato.")
   (PERSONAE ("Pompilius" "Brassicanus")))
 ))

(assert (equalp (parse-cue '((bar-group "Br") "At" "idem," (slash-group "ne") "sis" star "inscius,"))

                (make-cue "Br" (make-rich-text
                                 (list (make-rich-word "At")
                                       (make-rich-word "idem,")
                                       (make-rich-word "ne" 'i)
                                       (make-rich-word "sis")
                                       'note-sign
                                       (make-rich-word "inscius,"))))
                ))


(assert (string= (with-output-to-string (*tex-stream*)
                   (to-tex "tu & ego"))
                 "tu \\& ego"))


(assert (string= (with-output-to-string (*tex-stream*)
                   (to-tex (make-cue "Po" (make-rich-text (list (make-rich-word "Unde")
                                                                (make-rich-word "nobis" 'i)
                                                                (make-rich-word "petasatus?" 'i))))))
"\\textsc{Po}. Unde \\emph{nobis petasatus?}
"
         ))

(assert (equal (with-input-from-string (in "wibble wobble /foo bar baz/ qux")
  (loop for token = (coll-read in)
        while token
        collect token))
       '("wibble" "wobble" (SLASH-GROUP "foo" "bar" "baz") "qux")
       ))

(assert (equal (with-input-from-string (in "foo bar baz/ qux")
         (coll-read-delimited #\/ in))
       '("foo" "bar" "baz")))

(assert (equal (with-input-from-string (in "foo ba.r baz. qux")
  (coll-read-delimited #\. in))
       '("foo" "ba")
       ))

(assert (equal (with-input-from-string
                 (s "
foo
bar
baz
`
qux")
                    (coll-read-delimited-lines "`" s)
                    ) '("foo" "bar" "baz")))

(assert (equal (with-input-from-string
  (s "
foo
bar
baz
```
qux")
(coll-read-delimited-lines "```" s)
)
  '("foo" "bar" "baz")
  ))

(assert (equalp (multiple-value-list (parse-verse '((backquote-group "foo bar baz" "*qux quux") "wibble" "wobble")))
                (list (make-verse (list (make-rich-text (list (make-rich-word "foo")
                                                              (make-rich-word "bar")
                                                              (make-rich-word "baz")))
                                        (make-rich-text (list 'note-sign
                                                              (make-rich-word "qux")
                                                              (make-rich-word "quux")))))
                      '("wibble" "wobble"))))


(assert (equalp (parse-rich-text '("foo" (slash-group "bar" star "baz") "qux"))
                (make-rich-text (list (make-rich-word "foo")
                                      (make-rich-word "bar" 'i)
                                      'note-sign
                                      (make-rich-word "baz" 'i)
                                      (make-rich-word "qux")))))
